﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Common.Data.Converters="clr-namespace:Imagin.Common.Data.Converters;assembly=Imagin.Common"
    xmlns:Common.Extensions="clr-namespace:Imagin.Common.Extensions;assembly=Imagin.Common"
    xmlns:Controls.Common="clr-namespace:Imagin.Controls.Common;assembly=Imagin.Controls.Common"
    xmlns:Controls.Common.Extensions="clr-namespace:Imagin.Controls.Common.Extensions;assembly=Imagin.Controls.Common">
    <Style TargetType="{x:Type Expander}">
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Foreground" Value="{DynamicResource Expander.Foreground}" />
        <Setter Property="Background" Value="{DynamicResource Expander.Background}" />
        <Setter Property="BorderBrush" Value="{DynamicResource Expander.Border}" />
        <Setter Property="Padding" Value="5,7" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Expander}">
                    <DockPanel HorizontalAlignment="{TemplateBinding HorizontalAlignment}">
                        <ToggleButton 
                            DockPanel.Dock="Top" 
                            Background="{TemplateBinding Background}" 
                            BorderBrush="{TemplateBinding BorderBrush}" 
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            Content="{TemplateBinding Header}" 
                            IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" 
                            OverridesDefaultStyle="True"
                            Padding="{TemplateBinding Padding}">
                            <ToggleButton.Template>
                                <ControlTemplate TargetType="{x:Type ToggleButton}">
                                    <Border 
                                        x:Name="ExpanderButtonBorder" 
                                        Background="{TemplateBinding Background}" 
                                        BorderBrush="{TemplateBinding BorderBrush}" 
                                        BorderThickness="{TemplateBinding BorderThickness}">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <Rectangle 
                                                x:Name="PART_Arrow" 
                                                Width="16" 
                                                Height="16" 
                                                Fill="{DynamicResource Brush.Image}" 
                                                RenderTransformOrigin="0.5, 0.5">
                                                <Rectangle.OpacityMask>
                                                    <ImageBrush ImageSource="pack://application:,,,/Imagin.Styles;component/Images/32ArrowDown.png"/>
                                                </Rectangle.OpacityMask>
                                                <Rectangle.RenderTransform>
                                                    <RotateTransform Angle="-90"/>
                                                </Rectangle.RenderTransform>
                                            </Rectangle>
                                            <ContentPresenter 
                                                x:Name="HeaderContent" 
                                                Grid.Column="1" 
                                                ContentSource="Content" 
                                                Margin="{TemplateBinding Padding}"/>
                                        </Grid>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsChecked" Value="True">
                                            <Trigger.EnterActions>
                                                <BeginStoryboard>
                                                    <Storyboard>
                                                        <DoubleAnimation Storyboard.TargetName="PART_Arrow" Storyboard.TargetProperty="(Path.RenderTransform).(RotateTransform.Angle)" To="0" Duration="0:0:0.4"/>
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </Trigger.EnterActions>
                                            <Trigger.ExitActions>
                                                <BeginStoryboard>
                                                    <Storyboard>
                                                        <DoubleAnimation Storyboard.TargetName="PART_Arrow" Storyboard.TargetProperty="(Path.RenderTransform).(RotateTransform.Angle)" To="-90" Duration="0:0:0.4"/>
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </Trigger.ExitActions>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </ToggleButton.Template>
                        </ToggleButton>
                        <ContentPresenter 
                            x:Name="PART_Content"
                            Visibility="Collapsed"
                            DockPanel.Dock="Bottom"/>
                    </DockPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="True">
                            <Setter TargetName="PART_Content" Property="Visibility" Value="Visible"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>